import { createRouter, createWebHashHistory } from 'vue-router'


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/profile' },
    { path: '/profile', component: () => import('@/views/ProfileEdit.vue'), meta: { title: '个人资料' } },
    { path: '/address', component: () => import('@/views/AddressManager.vue'), meta: { title: '地址列表' } },
    { path: '/address/edit/:id?', component: () => import('@/views/AddressEdit.vue'), meta: { title: '地址管理' } },
  ]
})

// 路由的全局前置守卫,访问的任何路径都会进入前置守卫，离开的时候全局后置守卫
// to到哪个地方去,from从哪个地方来
//, from, next
router.beforeEach((to) => {
  // console.log('进入全局前置守卫', to);
  // 修改网页标题
  document.title = to.meta.title as string
})

// 路由的全局后置守卫
// router.afterEach((to) => {
//   console.log('进入全局后置守卫');
//   // document.title = to.meta.title as string

// })

export default router
